package com.piggy.logi.sys.controller;

import java.util.List;
import java.util.Arrays;

import com.piggy.common.log.annotation.LogiLog;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.vo.LogiScheduleFeeVo;
import com.piggy.logi.sys.bo.LogiScheduleFeeQueryBo;
import com.piggy.logi.sys.bo.LogiScheduleFeeEditBo;
import com.piggy.logi.sys.service.ILogiScheduleFeeService;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.piggy.common.core.domain.R;
import java.lang.Integer;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * 调度线路分段费用Controller
 *
 * @author piggy
 * @date 2023-09-13
 */
@Api(value = "调度线路分段费用控制器", tags = {"调度线路分段费用管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/schedulefee")
public class LogiScheduleFeeController extends BaseController {

    private final ILogiScheduleFeeService iLogiScheduleFeeService;

    /**
     * 查询调度线路分段费用列表
     */
    @ApiOperation("查询调度线路分段费用列表")
    //@SaCheckPermission("sys:schedulefee:list")
    @PostMapping("/list")
    public TableDataInfo<LogiScheduleFeeVo> list(@Validated @RequestBody LogiScheduleFeeQueryBo bo) {
        return iLogiScheduleFeeService.queryPageList(bo);
    }

    /**
     * 导出调度线路分段费用列表
     */
    @ApiOperation("导出调度线路分段费用列表")
    //@SaCheckPermission("sys:schedulefee:export")
    @LogiLog(title = "调度线路分段费用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiScheduleFeeQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiScheduleFeeVo> list = iLogiScheduleFeeService.queryList(bo);
        ExcelUtil<LogiScheduleFeeVo> util = new ExcelUtil<LogiScheduleFeeVo>(LogiScheduleFeeVo.class);
        util.exportExcel(response, list, "调度线路分段费用");
    }

    /**
     * 获取调度线路分段费用详细信息
     */
    @ApiOperation("获取调度线路分段费用详细信息")
    //@SaCheckPermission("sys:schedulefee:query")
    @GetMapping("/{id}")
    public R<LogiScheduleFeeVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iLogiScheduleFeeService.queryById(id));
    }

    /**
     * 新增调度线路分段费用
     */
    @ApiOperation("新增调度线路分段费用")
    //@SaCheckPermission("sys:schedulefee:add")
    @LogiLog(title = "调度线路分段费用", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiScheduleFeeVo> add(@Validated @RequestBody LogiScheduleFeeEditBo bo) {
        return R.ok(iLogiScheduleFeeService.insertByAddBo(bo));
    }

    /**
     * 修改调度线路分段费用
     */
    @ApiOperation("修改调度线路分段费用")
    //@SaCheckPermission("sys:schedulefee:edit")
    @LogiLog(title = "调度线路分段费用", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiScheduleFeeVo> edit(@Validated @RequestBody LogiScheduleFeeEditBo bo) {
        return R.ok(iLogiScheduleFeeService.updateByEditBo(bo));
    }

    /**
     * 删除调度线路分段费用
     */
    @ApiOperation("删除调度线路分段费用")
    //@SaCheckPermission("sys:schedulefee:remove")
    @LogiLog(title = "调度线路分段费用" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return R.ok(iLogiScheduleFeeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
